package com.workcell.workdata.xthings.controller;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.workcell.workdata.common.core.util.R;
import com.workcell.workdata.common.security.annotation.Inner;
import com.workcell.workdata.xthings.dto.DeviceRunLogVo;
import com.workcell.workdata.xthings.entity.DeviceRunLog;
import com.workcell.workdata.xthings.service.DeviceRunLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 运行日志
 *
 * @author guogyu
 * @date 2023-05-09 09:30:50
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/devicerunlog" )
@Api(value = "devicerunlog", tags = "运行日志")
public class DeviceRunLogController {

    private final DeviceRunLogService deviceRunLogService;

    /**
     * 新添/修改日志
     * @param deviceRunLog
     * @return
     */
    @Inner
    @ApiOperation(value = "新添/修改日志", notes = "新添/修改日志")
	@ResponseBody
    @PostMapping
    public R<DeviceRunLog> saveOrUpdate(@RequestBody DeviceRunLog deviceRunLog) {
		deviceRunLogService.saveOrUpdate(deviceRunLog);
        return R.ok(deviceRunLog);
    }

	@ApiOperation(value = "模糊分页查询", notes = "模糊分页查询")
	@GetMapping("/vaguePage")
	public R<Page<DeviceRunLog>> vaguePage(DeviceRunLogVo.SelectDataVo selectDataVo) {
		Assert.isTrue(ObjectUtil.isAllEmpty(selectDataVo.getStartTime(),selectDataVo.getEndTime()) || ObjectUtil.isAllNotEmpty(selectDataVo.getStartTime(),selectDataVo.getEndTime()),"请选择起止时间");
		return R.ok(deviceRunLogService.vaguePage(selectDataVo));
	}
}
